package com.xzakota.minesweeper.model.entity;

import com.xzakota.minesweeper.model.Observable;

import java.util.Objects;

/**
 * 游戏格子实体类
 *
 * @author Xzakota
 */
public class CellBean extends Observable {
    public static final int MARK_NO = 0;
    public static final int MARK_MAYBE = 1;
    public static final int MARK_SURE = 2;
    public static final int MARK_IS_A_MINE = 3;
    public static final int MARK_WRONG_MARK = 4;

    public static final int STATUS_UN_SWEEP = 1;
    public static final int STATUS_WILL_SWEEP = 2;
    public static final int STATUS_SWEPT = 3;

    public final int x;
    public final int y;
    public boolean hasMine;
    public boolean froze;
    public int status = STATUS_UN_SWEEP;
    public int mark = MARK_NO;
    public int roundMineAmount;

    public CellBean(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public void setChanged() {
        super.setChanged();
        super.notifyObservers();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        CellBean cellBean = (CellBean) o;
        return x == cellBean.x && y == cellBean.y && hasMine == cellBean.hasMine && froze == cellBean.froze && status == cellBean.status && mark == cellBean.mark && roundMineAmount == cellBean.roundMineAmount;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y, hasMine, froze, status, mark, roundMineAmount);
    }

    @Override
    public String toString() {
        return "CellBean{" +
                "x=" + x +
                ", y=" + y +
                ", hasMine=" + hasMine +
                ", froze=" + froze +
                ", status=" + status +
                ", mark=" + mark +
                ", roundMineAmount=" + roundMineAmount +
                '}';
    }
}
